//
//  ViewController.m
//  Background changer
//
//  Created by iD Student on 7/9/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	colorList = [[NSMutableArray alloc] init];
    [colorList addObject:@"red"];
    [colorList addObject:@"blue"];
    [colorList addObject:@"green"];
    [colorList addObject:@"orange"];
    [colorList addObject:@"brown"];
    [colorList addObject:@"purple"];
    [colorList addObject:@"yellow"];
    
    colorPicker.delegate = self;
    colorPicker.dataSource = self;
}
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return colorList.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [colorList objectAtIndex:row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    selectedRow = row;
}

-(IBAction)changePressed:(id)sender
{
    NSString *selectedColor = [colorList objectAtIndex:selectedRow];
    if([selectedColor compare:@"red"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor redColor]];
    }
    if([selectedColor compare:@"blue"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor blueColor]];
    }
    if([selectedColor compare:@"green"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor greenColor]];
    }
    if([selectedColor compare:@"yellow"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor yellowColor]];
    }
    if([selectedColor compare:@"orange"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor orangeColor]];
    }
    if([selectedColor compare:@"purple"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor purpleColor]];
    }
    if([selectedColor compare:@"brown"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor brownColor]];
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
